{include('Layout/header')}
<div class="row row-bgcolor">
    <div class='col-md-12 content-title'>
        <h3>编辑用户</h3>
    </div>
    <div class='col-md-6 content col-md-offset-3'>
        <form action="{\Rexzy::url('admin/useredit')}">
            <div class="form-group">
                <label for="name">用户名</label>
                <input type="text" class="form-control" id="name" name="name" placeholder="用户名" value="{$name}" >
                <p id="name_note" class="input-note">请输入4-16个字符的用户名，用于用户登录</p>
            </div>
            <div class="form-group">
                <label for="screenName">昵称</label>
                <input type="text" class="form-control" id="screenName" name="screenName" value='{$screenName}' >
                <p id="screenName_note" class="input-note">可用于前台显示，为空时默认为用户名</p>
            </div>
            <div class="form-group">
                <label for="newpaswd">新密码</label>
                <input type="password" class="form-control" id="newpaswd" name="newpaswd" >
                <p id="password_note" class="input-note">请输入6-20个字符的新密码</p>
            </div>
            <div class="form-group">
                <label for="confNewPaswd" >确认新密码</label>
                <input type="password" class="form-control" id="confNewPaswd" name="confNewPaswd">
                <p id="confPassword_note" class="input-note">请再次输入新密码，并确保与上面输入的新密码一致</p>
            </div>
            <div class="form-group">
                <label for="emai1">电子邮箱地址</label>
                <input type="email" class="form-control" id="email" name="email" value="{$email}">
                <p id="mail_note" class="input-note">请输入电子邮箱地址</p>
            </div>
            <div class="form-group">
                <label for="oldpaswd">原用户密码</label>
                <input type="password" class="form-control" id="oldpaswd" name="oldpaswd">
                <p id="password_note" class="input-note">编辑用户必须输入原用户密码</p>
            </div>
            <div class="form-group">
                <label for="grop">用户组</label>
                <select name="group" id="group" class="form-control user-group">
                    <option value="subscriber">关注者</option>
                    <option value="contributor">贡献者</option>
                    <option value="editor">编辑</option>
                    <option value="administrator">管理员</option>
                </select>
                <p id="mail_note" class="input-note">不同的用户组拥有不同的权限.</p>
            </div>
            <input type="text" class="form-control" id="userid" name="userid"  value="{$userid}" style="display:none;">
            <button type="submit" class="btn btn-info edit-user">编辑用户</button>
            <a href="{\Rexzy::url('admin/userlist')}" class="return-userlist">返回用户列表</a>
        </form>
    </div>
</div>

<script>
    $(function() {
        var group = "{$usergroup}";
        $("#group > option").each( function() {
            if ( $(this).val() == group ) {
                this.selected = 'selected';
            }
        });
    });
    
    // 用户信息更新成功后跳转函数
    function updateLocation() {
        location = "{\Rexzy::url('admin/userlist')}";
    }
    
    formVerification('form', [
        {
            id:'name',
            required: true,
            errormessage: '用户名不能为空',
            rules:[
                {
                    rule:function( val) {
                    if ( ( val.length < 4 ) || (val.length >16 ) ) {
                        return false;
                    }
                    },
                    error: "请输入4-16个字符的用户名",
                }
            ]
        },
        {
            id : 'screenName',
            required : false,
        },
        {
            id: 'oldpaswd',
            required: true,
            errormessage : '请输入原用户密码'
        },
        {
            id : 'newpaswd',
            required: false,
            rules: [
                {
                    rule : function(val) {
                        if ( val.length < 4 ) {
                        return false;
                        }
                    },
                    error: "请输入4个或以上字符的密码",
                }
            ]
        },
        {
            id : 'confNewPaswd',
            required: false,
            rules: [
                {
                    rule:function(val) {
                        if ( val !== $("#newpaswd" ).val() ) {
                            return false;
                        }
                    },
                    error: "密码不一致"
                }
            ]
        },
        {
            id: 'email',
            required: false,
        },
        {
            id:'userid',
            required: true
        },
        {
            id: 'group',
            require: true,
        }
    ], updateLocation );
</script>
{include('Layout/footer')}